<?php defined('BASEPATH') OR exit('No direct script access allowed');

class engineerDashboard extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}
        $this->load->library('form_validation');		
		$this->load->model('engineer_dashboard_model');
	}
        	
	//redirect if needed, otherwise display the user list
	function index()
	{ 
	$id=$this->session->userdata['user_id'];
	$this->engineer_dashboard_model->insert_image($id);
	  $this->data['no_case']= $this->engineer_dashboard_model->get_month_caseid($id);
      $this->data['no_warranty']=$this->engineer_dashboard_model->get_warranty($id);
	   $this->data['no_nonwarranty']=$this->engineer_dashboard_model->get_nonwarranty($id);
	   $this->data['no_diagnosis']= $this->engineer_dashboard_model->get_month_diagnosis($id);
	  
	    $this->data['no_repair']= $this->engineer_dashboard_model->get_month_repair($id);
   
       $this->data['image']=$this->engineer_dashboard_model->get_image($id)->row();
      $this->data['tabler']=$this->engineer_dashboard_model->get_detail_repair($id);
	    $this->data['tabled']=$this->engineer_dashboard_model->get_detail_diagnosis($id);
	     $this->data['table2d']=$this->engineer_dashboard_model->get_nonwarranty_diagnosis($id);
		  $this->data['table2r']=$this->engineer_dashboard_model->get_nonwarranty_repair($id);
		$meta['page_title'] = 'Engineer Dashboard';
		$this->load->view('common/header',$meta);		
		$this->load->view('dashboard',$this->data);
		$this->load->view('common/footer');
	}

   public function update_userimage()
   {
   $config['upload_path'] = './user_image/';
		$config['allowed_types'] = 'gif|jpg|png|jpeg|doc|txt|pdf|zip|rar';
		$config['max_size']	= '20480';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';
		$this->load->library('upload',$config);
        $new_img =  $_FILES['user_photo']['name'];
		$id=$this->session->userdata['user_id'];
		$new_img=$id.$new_img;
        $tmpName  = $_FILES['user_photo']['tmp_name'];  
       
	   $this->engineer_dashboard_model->update_image($id,$new_img);
        $data =array( 'upload_data' => move_uploaded_file($tmpName,"./user_image/$new_img"));
     redirect('engineer/engineerDashboard');
		}

public function update_profile()
{
$id=$this->session->userdata['user_id'];
$this->engineer_dashboard_model->insert_image($id);
$this->data['image']=$this->engineer_dashboard_model->get_image($id)->row();
$this->data['profile']=$this->engineer_dashboard_model->get_profile($id)->row();
$meta['page_title'] = 'Profile';
$this->load->view('common/header',$meta);		
$this->load->view('profile',$this->data);
$this->load->view('common/footer');

}
public function update_profileData()
{
$id=$this->session->userdata['user_id'];
$this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean');
$this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('phone', 'First Part of Phone', 'required|min_length[10]|max_length[10]');
$this->form_validation->set_rules('address', 'Address', 'required|xss_clean');
$this->form_validation->set_rules('company_name', 'Company Name', 'required|xss_clean');

		if ($this->form_validation->run() == true)
		{
$username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name'));
$insert=array('first_name'=>$_REQUEST['first_name'],'last_name'=>$_REQUEST['last_name'],'username'=>$username,'email'=>$_REQUEST['email'],'address'=>$_REQUEST['address'],'phone'=>$_REQUEST['phone'],'company'=>$_REQUEST['company_name']);

$this->engineer_dashboard_model->update_profile($insert,$id);
redirect('/engineer/engineerDashboard');
}
else{
redirect('/engineer/engineerDashboard/update_profile');

}}
public function get_diagnosis()
{
$id=$this->session->userdata['user_id'];
$data=$this->engineer_dashboard_model->get_diagnosis($id);
echo $data;
}
public function get_repair()
{
$id=$this->session->userdata['user_id'];
$data=$this->engineer_dashboard_model->get_repair($id);
echo $data;
}




	
}

